HAL RTC types migration

This section provides information about the HAL RTC types migration .

HAL RTC state type definition

HAL1

HAL2

typedef enum
{
  HAL_RTC_STATE_RESET
  HAL_RTC_STATE_READY
  HAL_RTC_STATE_BUSY
  HAL_RTC_STATE_TIMEOUT
  HAL_RTC_STATE_ERROR
} HAL_RTCStateTypeDef;

Removed .

Note

The handle and state machine are removed in HAL2.

HAL RTC callback ID type definition

HAL1

HAL2

typedef enum
{
  HAL_RTC_ALARM_A_EVENT_CB_ID
  HAL_RTC_ALARM_B_EVENT_CB_ID
  HAL_RTC_TIMESTAMP_EVENT_CB_ID
  HAL_RTC_WAKEUPTIMER_EVENT_CB_ID
  HAL_RTC_SSRU_EVENT_CB_ID
  HAL_RTC_TAMPER1_EVENT_CB_ID
  HAL_RTC_TAMPER2_EVENT_CB_ID
  HAL_RTC_TAMPER3_EVENT_CB_ID
  HAL_RTC_TAMPER4_EVENT_CB_ID
  HAL_RTC_TAMPER5_EVENT_CB_ID
  HAL_RTC_TAMPER6_EVENT_CB_ID
  HAL_RTC_TAMPER7_EVENT_CB_ID
  HAL_RTC_TAMPER8_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER7_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER8_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER9_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER11_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER12_EVENT_CB_ID
  HAL_RTC_INTERNAL_TAMPER13_EVENT_CB_ID
  HAL_RTC_MSPINIT_CB_ID
  HAL_RTC_MSPDEINIT_CB_ID
} HAL_RTC_CallbackIDTypeDef;

Removed .

Note

The callback registration in HAL2 is handled by specific functions for each RTC event.

The update from HAL 1 to HAL 2 involves a significant change in the way callback functions are registered for RTC events.

Related concept: Individual callback registration APIs replace global register and unregister functions


HAL RTC initialization type definition

In HAL1, the RTC initialization and configuration were managed using a single structure RTC_InitTypeDef, which included various fields for different aspects of the RTC configuration. This approach could be cumbersome to manage and understand, especially as the configuration grew more complex.

In HAL2, the RTC configuration has been split into multiple smaller structures, each focusing on a specific aspect of the configuration.

HAL1

HAL2

typedef struct
{
  uint32_t HourFormat;
  uint32_t AsynchPrediv;
  uint32_t SynchPrediv;
  uint32_t OutPut;
  uint32_t OutPutRemap;
  uint32_t OutPutPolarity;
  uint32_t OutPutType;
  uint32_t OutPutPullUp;
  uint32_t BinMode;
  uint32_t BinMixBcdU;
} RTC_InitTypeDef;
typedef struct
{
  hal_rtc_mode_t mode;
  uint32_t  asynch_prediv;
  uint32_t  synch_prediv;
  hal_rtc_bcd_update_t bcd_update;
} hal_rtc_config_t;

typedef struct
{
  hal_rtc_calendar_hour_format_t       hour_format;
  hal_rtc_calendar_shadow_reg_bypass_t bypass_shadow_register;
} hal_rtc_calendar_config_t;

typedef struct
{
  hal_rtc_output_tampalarm_polarity_t polarity;
  hal_rtc_output_tampalarm_type_t     type;
  hal_rtc_output_tampalarm_pullup_t   pullup;
} hal_rtc_output_tampalarm_config_t;

HAL RTC time type definition

In HAL1, the RTC time configuration was managed using a single structure RTC_TimeTypeDef, which included various fields for different aspects of the time configuration. This approach could be cumbersome to manage and understand, especially as the configuration grew more complex.

In HAL2, the RTC time configuration has been split into a more focused structure hal_rtc_time_t.

HAL1

HAL2

typedef struct
{
  uint8_t Hours;
  uint8_t Minutes;
  uint8_t Seconds;
  uint8_t TimeFormat;
  uint32_t SubSeconds;
  uint32_t SecondFraction;
  uint32_t DayLightSaving;
  uint32_t StoreOperation;
} RTC_TimeTypeDef;
typedef struct
{
  hal_rtc_time_format_am_pm_t am_pm;
  uint32_t                    subsec;
  uint32_t                    microsec;
  uint32_t                    millisec;
  uint32_t                    hour;
  uint32_t                    min;
  uint32_t                    sec;
} hal_rtc_time_t;

HAL RTC date type definition

In HAL1, the RTC date configuration was managed using a single structure RTC_DateTypeDef, which included fields for the weekday, month, date, and year.

In HAL2, the RTC date configuration has been updated to use a more focused structure hal_rtc_date_t. This change improves modularity, readability, and maintainability. Using specific enumerations for each field also enhances type safety and clarity.

HAL1

HAL2

typedef struct
{
  uint8_t WeekDay;
  uint8_t Month;
  uint8_t Date;
  uint8_t Year;
} RTC_DateTypeDef;
typedef struct
{
  hal_rtc_weekday_t wday;
  hal_rtc_month_t   mon;
  uint32_t          mday;
  uint32_t          year;
} hal_rtc_date_t;

HAL RTC alarm type definition

In HAL1, the RTC alarm configuration was managed using a single structure, RTC_AlarmTypeDef, encompassing various fields for time, masks, and flags. This approach could become cumbersome and difficult to manage as the configuration grew more complex.

In HAL2, the RTC alarm configuration has been divided into two distinct structures: hal_rtc_alarm_config_t for subseconds auto-reload and auto-clear settings, and hal_rtc_alarm_date_time_t for time, mask, and day selection.

HAL1

HAL2

typedef struct
{
  RTC_TimeTypeDef AlarmTime;
  uint32_t AlarmMask;
  uint32_t AlarmSubSecondMask;
  uint32_t BinaryAutoClr;
  uint32_t AlarmDateWeekDaySel;
  uint8_t AlarmDateWeekDay;
  uint32_t FlagAutoClr;
  uint32_t Alarm;
} RTC_AlarmTypeDef;
typedef struct
{
  hal_rtc_alarm_subseconds_auto_reload_t subsec_auto_reload;
  hal_rtc_alarm_auto_clear_t             auto_clear;
} hal_rtc_alarm_config_t;

typedef struct
{
  hal_rtc_time_t                     time;
  uint32_t                           mask;
  uint32_t                           subsec_mask;
  hal_rtc_alarm_day_type_selection_t mday_wday_selection;
  hal_rtc_alarm_day_t                wday_mday;
} hal_rtc_alarm_date_time_t;

HAL RTC handle type definition

HAL1

HAL2

RTC_HandleTypeDef

The handle is removed in HAL2


HAL RTC callback type definition

HAL1

HAL2

pRTC_CallbackTypeDef

The callback typedef is removed in HAL2.

Important

Find the following TAMPER types in a separate IP files TAMP as the driver RTC is now divided into two separate drivers (RTC & TAMP).


HAL RTC tamper type definition

In HAL1, the tamper configuration was managed using a single structure RTC_TamperTypeDef, which included various fields for tamper settings such as trigger, no erase, mask flag, filter, sampling frequency, precharge duration, tamper pull-up, and timestamp on tamper detection.

In HAL2, the tamper configuration has been split into two separate structures: hal_tamp_passive_config_t and hal_tamp_passive_individual_config_t.

HAL1

HAL2

typedef struct
{
  uint32_t Tamper;
  uint32_t Trigger;
  uint32_t NoErase;
  uint32_t MaskFlag;
  uint32_t Filter;
  uint32_t SamplingFrequency;
  uint32_t PrechargeDuration;
  uint32_t TamperPullUp;
  uint32_t TimeStampOnTamperDetection;
} RTC_TamperTypeDef;
typedef struct
{
  hal_tamp_passive_pull_up_precharge_state_t precharge;
  hal_tamp_passive_pull_up_precharge_duration_t precharge_duration;
  hal_tamp_passive_filter_t type_activation;
  hal_tamp_passive_sample_frequency_t sample_frequency;
} hal_tamp_passive_config_t;

typedef struct
{
  hal_tamp_passive_trigger_t trigger;
  hal_tamp_passive_secrets_erase_t erase_secrets;
  hal_tamp_passive_mask_t masked;
} hal_tamp_passive_individual_config_t;

HAL RTC active tamper type definition

In HAL1, the active tamper configuration was managed using a single structure RTC_ActiveTampersTypeDef.

In HAL2, the active tamper configuration has been split into two separate structures: hal_tamp_active_config_t and hal_tamp_active_individual_config_t.

HAL1

HAL2

typedef struct
{
  uint32_t Enable;
  uint32_t Interrupt;
  uint32_t Output;
  uint32_t NoErase;
  uint32_t MaskFlag;
} RTC_ATampInputTypeDef;

typedef struct
{
  uint32_t ActiveFilter;
  uint32_t ActiveAsyncPrescaler;
  uint32_t TimeStampOnTamperDetection;
  uint32_t ActiveOutputChangePeriod;
  uint32_t Seed[RTC_ATAMP_SEED_NB_UINT32];
  RTC_ATampInputTypeDef TampInput[RTC_TAMP_NB];
} RTC_ActiveTampersTypeDef;
typedef struct
{
  hal_tamp_active_secrets_erase_t erase_secrets;
  hal_tamp_active_output_tampers_t tamper_output;
} hal_tamp_active_individual_config_t;

typedef struct
{
  uint32_t output_period;
  hal_tamp_active_filter_state_t filter;
  hal_tamp_active_prescaler_t asynchronous_prescaler;
  hal_tamp_active_output_shared_t shared_output;
} hal_tamp_active_config_t;

/* The interruption, enable and seed parameters are now handled with this functions in HAL2 */
HAL_TAMP_ACTIVE_Start(uint32_t tampers, uint32_t interruption, const uint32_t *p_seeds)

/* User can update the seed separately with: */
HAL_TAMP_ACTIVE_SetSeed(const uint32_t *p_seeds)

HAL RTC internal tamper type definition

In HAL1, the internal tamper configuration was managed using a single structure RTC_InternalTamperTypeDef.

In HAL2, the internal tamper configuration has been simplified and updated to use a structure named hal_tamp_internal_individual_config_t.

HAL1

HAL2

typedef struct
{
  uint32_t IntTamper;
  uint32_t TimeStampOnTamperDetection;
  uint32_t NoErase;
} RTC_InternalTamperTypeDef;
typedef struct
{
  hal_tamp_internal_secrets_erase_t erase_secrets;
} hal_tamp_internal_individual_config_t;

/* Parameters IntTamper and NoErase, are now handled with this functions in HAL2 */
hal_status_t HAL_TAMP_INTERNAL_SetConfigTampers(uint32_t internal_tampers, const hal_tamp_internal_individual_config_t *p_config)

/* TimeStampOnTamperDetection parameter is now handled by this function in HAL2*/
HAL_RTC_TIMESTAMP_EnableTamperSource(void) or HAL_RTC_TIMESTAMP_DisableTamperSource(void)

HAL RTC secure type definition

HAL1

HAL2

typedef struct
{
  uint32_t rtcSecureFull;
  uint32_t rtcNonSecureFeatures;
  uint32_t tampSecureFull;
  uint32_t backupRegisterStartZone2;
  uint32_t backupRegisterStartZone3;
  uint32_t MonotonicCounterSecure;
} RTC_SecureStateTypeDef;

Not yet implemented


HAL RTC privilege type definition

HAL1

HAL2

typedef struct
{
  uint32_t rtcPrivilegeFull;
  uint32_t rtcPrivilegeFeatures;
  uint32_t tampPrivilegeFull;
  uint32_t backupRegisterPrivZone;
  uint32_t backupRegisterStartZone2;
  uint32_t backupRegisterStartZone3;
  uint32_t MonotonicCounterPrivilege;
} RTC_PrivilegeStateTypeDef;

Not yet implemented